package com.playball.lottery.nt.animal;

import java.io.IOException;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Administrator on 2017/3/15.
 */

public class O2OServiceImpl {

    private BaseServiceImpl2 baseService;

    public O2OServiceImpl() {
        this.baseService = new BaseServiceImpl2();
    }


    /**
     * 拼接基本的参数URL字符串

     * @param platformVersion
     * @param UserID
     * @param platformCode
     * @param sign
     * @param appVersion
     * @param cmdName
      * @param uuid
     * @param action
     * @return
     */
    /**
     * 获取广告位数据
     */

    public  String  getAdvertisingData(){
        String result = "";
        String urlOfBasic = baseService.getURLOfBasic(
                "6.0",
                "ODM",
                "Android",
                "6AC3583C15FEB7B931172E8E6AF71937",
                "1.0",
                "app_zz",
                "3C075461B9B0",
                "23");
        String urlOfParams = baseService.getURLOfParams("");
        String url = baseService.prefixUrl + urlOfBasic + "&" + urlOfParams;
        // System.out.println("url is " + url);
        OkHttpClient client = new OkHttpClient();
//String url2="http://mobile.tcaio2o.com/MobileHandler.ashx?platformVersion=6.0&UserID=ODMw&platformCode=Android&sign=6AC3583C15FEB7B931172E8E6AF71937&appVersion=1.0&cmdName=app_zz&uuid=3C075461B9B0&action=23&"+urlOfParams;
        Request request = new Request.Builder()
                .url(url)
                .build();

        try {
            Response response = client.newCall(request).execute();
            result = response.body().string();
        } catch (IOException e) {
            e.printStackTrace();
        }
        //如果response回傳是null, 就代表timeout或 沒有網路

        return result;
    }

    /**
     * 获取广告位的URL
     *
     * @return
     */
    public String getURLOfAdvertising() {
        String urlOfBasic = baseService.getURLOfBasic(
                "6.0",
                "ODM",
                "Android",
                "6AC3583C15FEB7B931172E8E6AF71937",
                "1.0",
                "app_zz",
                "3C075461B9B0",
                "23");
        String urlOfParams = baseService.getURLOfParams("");
        String url = baseService.prefixUrl + urlOfBasic + "&" + urlOfParams;
//        String url2="http://mobile.tcaio2o.com/MobileHandler.ashx?platformVersion=6.0&UserID=ODMw&platformCode=Android&sign=6AC3583C15FEB7B931172E8E6AF71937&appVersion=1.0&cmdName=app_zz&uuid=3C075461B9B0&action=23&"+urlOfParams;

        return url;
    }



    /**
     * 获取开奖的URL
     *
     * @return
     */
    public String getURLOfAdvertising2() {
        String result;

        // System.out.println(GetJsonData.urlPath);
        String url = baseService.prefixUrl + "platformVersion=6.0&UserID=ODMw&platformCode=Android&sign=6AC3583C15FEB7B931172E8E6AF71937&appVersion=1.0&cmdName=app_zz&uuid=3C075461B9B0&action=23&params={\"LSID\":3}";
        // System.out.println("url is " + url);
        result = url;
        return result;
    }
}
